package com.test.uiapp2.function.Settings;

import android.util.Log;

import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;

import com.test.uiapp2.base.TestBase;
import com.test.uiapp2.element.Base.BaseElement;
import com.test.uiapp2.element.Settings.SettingsBluetoothElement;
import com.test.uiapp2.element.Settings.SettingsWlanElement;

public class SettingsBluetoothFcuntion extends TestBase {

    public  void Bluetooth_Start(){
        try {
            startSettings();
            if(getTest(SettingsBluetoothElement.BLUETOOTH).exists()){
                clickByText(SettingsBluetoothElement.BLUETOOTH);
                sleep(WAIT);
                UiObject status = getId(BaseElement.SETTINGS, SettingsBluetoothElement.SWITCH_WIDGET);
                if(status.exists()){
                    clickById(BaseElement.SETTINGS, SettingsBluetoothElement.SWITCH_WIDGET);
                    sleep(WAITTIME);
                    String StatusName = status.getText();
                    verify("蓝牙打开失败",StatusName.equals(SettingsBluetoothElement.START));
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public  void Bluetooth_Stop(){
        try {
            startSettings();
            if(getTest(SettingsBluetoothElement.BLUETOOTH).exists()){
                clickByText(SettingsBluetoothElement.BLUETOOTH);
                sleep(WAIT);
                UiObject status = getId(BaseElement.SETTINGS, SettingsBluetoothElement.SWITCH_WIDGET);
                if(status.exists()){
                    clickById(BaseElement.SETTINGS, SettingsBluetoothElement.SWITCH_WIDGET);
                    sleep(WAITTIME);
                    String StatusName = status.getText();
                    verify("蓝牙关闭失败",StatusName.equals(SettingsBluetoothElement.CLOSE));
                }

            }
        } catch (UiObjectNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void startSettings(){
        try {
            startApp(SettingsWlanElement.WLANNAME);
            sleep(SHOTWAIT);
            uiDevice.swipe(576,463,556,1146,10);
            if(getTest(SettingsBluetoothElement.CONNECTEDDEVICE).exists()){
                clickByText(SettingsBluetoothElement.CONNECTEDDEVICE);
                sleep(WAIT);
//                clickByText(SettingsBluetoothElement.CONNECTIONPREFERENCES);
            }else{
                verify("未进入设置界面",getTest(SettingsBluetoothElement.CONNECTEDDEVICE).exists());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
